<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('有权人签字管理列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>授权人机构号：</p>
                                <input type="text" name="orgCode" onclick="selectDeptTree()"  id="treeId" placeholder="请选择" />
                            </li>
                            <li>
                                <p>授权人姓名：</p>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <p>状态：</p>
                                <select name="status" th:with="type=${@dict.getType('signature_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="paea:signature:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="_edit()" shiro:hasPermission="paea:signature:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="paea:signature:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-primary multiple disabled" onclick="appro()" shiro:hasPermission="paea:signature:appro">
                    <i class="fa fa-save"></i> 审批
                </a>
                <a class="btn btn-warning single disabled" onclick="_stop()" shiro:hasPermission="paea:signature:end">
                    <i class="fa fa-close"></i> 停用
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="paea:signature:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('paea:signature:edit')}]];
        var removeFlag = [[${@permission.hasPermi('paea:signature:remove')}]];
        var statusDatas = [[${@dict.getType('signature_status')}]];
        var prefix = ctx + "paea/signature";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "有权人签字管理",
                //启用跳转至指定页
                showPageGo: true,
                //启用点击选中行
                clickToSelect: true,
                onDblClickRow:_onDblClickRow,
                detailView: true,
                onExpandRow : initChildTable,
                columns: [{
                    radio: true
                },
                {
                    field : 'id', 
                    title : '主键ID',
                    visible: false
                },
                {
                    field : 'orgCode', 
                    title : '机构号'
                },
                {
                    field : 'orgName', 
                    title : '机构名称'
                },
                {
                    field : 'position', 
                    title : '授权人职位'
                },
                {
                    field : 'name', 
                    title : '授权人姓名'
                },
                {
                    field : 'status', 
                    title : '状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field : 'startDate', 
                    title : '影像启用日期'
                },
                {
                    field : 'endDate', 
                    title : '影像停用日期'
                },
                {
                    field : 'createBy',
                    title : '创建者'
                },
                {
                    field : 'createTime', 
                    title : '创建时间'
                },
                {
                    field : 'updateBy', 
                    title : '更新者'
                },
                {
                    field : 'updateTime', 
                    title : '更新时间'
                },
                {
                    field : 'remark',
                    title : '备注',
                    visible : false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="viewDetail(\'' + row.id + '\')"><i class="fa fa-info"></i>详情</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        //子表视图
        function initChildTable(index, row, $detail) {
            var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
            //表头
            var columns = [{
                radio: true
            },
            {
                field : 'operateBy',
                title : '操作人'
            },
            {
                field : 'operateName',
                title : '操作人姓名'
            },
            {
                field : 'operateTime',
                title : '操作时间'
            },
            {
                field : 'operateContent',
                title : '操作类型'
            },
            {
                field : 'operateRemark',
                title : '意见'
            },
            {
                field : 'orgCode',
                title : '机构'
            },
            {
                field : 'orgName',
                title : '机构名'
            },
            {
                field : 'changeContent',
                title : '变更内容'
            }];
            var detailoptions = {
                url: ctx + "paea/signaturelog/querySignaturelogsBySignatureId",
                modalName: "有权人操作日志",
                method: 'post',
                sidePagination: "server",
                contentType: "application/x-www-form-urlencoded",
                queryParams : {
                    signatureId: row.id
                },
                rowStyle:detailRowStyle,//通过自定义函数设置行样式
                columns: columns
            };
            $(childTable).bootstrapTable(detailoptions);
        };
        //表格样式
        function detailRowStyle(row, index) {
            var style = {};
            style={css:{'color':'#0f2ded'}};
            return style;
        }
        function _onDblClickRow(row) {
            var url = prefix+"/view/"+row.id;
            //$.modal.openFull("查看详情", url);
            window.showModalDialog(url,"查看详情","dialogWidth=850px; dialogHeight=650px; help=no; status=no; scroll=yes; resizable=no;");
        }
        function viewDetail(id){
            var url = prefix+"/view/"+id;
            //$.modal.openFull("查看详情", url);
            window.showModalDialog(url,"查看详情","dialogWidth=850px; dialogHeight=650px; help=no; status=no; scroll=yes; resizable=no;");
        }
        function _edit(){
            var statuss = $.table.selectColumns("status");
            if(statuss.length<1 || statuss.length>1){
                alert("请选择一条数据");
                return;
            }
            if(statuss[0]==2){
                $.modal.alertWarning("已生效不能修改!");
                return;
            }else if(statuss[0]==3){
                $.modal.alertWarning("已停用不能修改!");
                return;
            }
            $.operate.edit();
        }
        //审批
        function appro(){
            var statuss = $.table.selectColumns("status");
            var ids = $.table.selectColumns("id");
            if(ids.length<1 || ids.length>1){
                alert("请选择一条数据");
                return;
            }
            if(statuss[0]==2){
                if(confirm("该笔有权人已生效，确定再审批吗？")){

                }else{
                    return;
                }
            }else if(statuss[0]==3){
                if(confirm("该笔有权人已停用，确定再审批吗？")){

                }else{
                    return;
                }
            }
            var url = prefix+"/appro/"+ids[0];
            //$.modal.openFull("查看详情", url);
            var returnValue = window.showModalDialog(url,window,"dialogWidth=850px; dialogHeight=650px; help=no; status=no; scroll=yes; resizable=no;");
            if(returnValue==1){
                $.table.refresh();
            }
        }
        //停用
        function _stop() {
            var statuss = $.table.selectColumns("status");
            var ids = $.table.selectColumns("id");
            if(ids.length<1 || ids.length>1){
                alert("请选择一条数据");
                return;
            }
            if(statuss[0]==3){
                alert("该笔有权人已停用，无需重复操作");
                return;
            }else if(statuss[0]!=2){
                alert("该笔有权人未生效，无需停用");
                return;
            }
            var data = {id:ids[0]}
            $.operate.post(prefix + "/signatureStop",data,function (result) {
                if (result.code == web_status.SUCCESS) {
                    alert(result.msg);
                    $.table.refresh();
                }else if (result.code == web_status.WARNING){
                    $.modal.alertWarning(result.msg);
                }else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            });
        }
        //选择机构
        function selectDeptTree() {
            var treeId = $("#treeId").val();
            var deptId = $.common.isEmpty(treeId) ? "00038" : $("#treeId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }
        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#treeId").val(body.find('#treeId').val());
                layer.close(index);
            }
        }
    </script>
</body>
</html>